//
//  StatusViewModel.m
//  weibo
//
//  Created by qiuming on 15/12/27.
//  Copyright © 2015年 qiuming. All rights reserved.
//

#import "StatusViewModel.h"

@implementation StatusViewModel

+ (instancetype)viewModelWithStatus:(StatusModel *)status {
    StatusViewModel *obj = [[self alloc]init];
    obj.status = status;
    return obj;
}
#pragma mark - 计算型属性
- (NSURL *)userAvatarURL {
    return [NSURL URLWithString:self.status.user.profile_image_url];
}

- (UIImage *)memberImage {
    if (self.status.user.mbrank > 0 && self.status.user.mbrank < 7) {
        NSString *memberName = [NSString stringWithFormat:@"common_icon_membership_level%zd", self.status.user.mbrank];
        return [UIImage imageNamed:memberName];
    }
    return nil;
}

- (UIImage *)verifiedImage {
    
    switch (self.status.user.verified_type) {
        case 0:
            return [UIImage imageNamed:@"avatar_vip"];
        case 2:
        case 3:
        case 5:
            return [UIImage imageNamed:@"avatar_enterprise_vip"];
        case 220:
            return [UIImage imageNamed:@"avatar_grassroot"];
        default:
            return nil;
    }
}

- (NSString *)repostsCountStr {
   
    NSString *result = [self countString:self.status.reposts_count];
    
    return result ?: @" 转发";
}

- (NSString *)commentsCountStr {
    
    NSString *result = [self countString:self.status.comments_count];
    
    return result ?: @" 评论";
}

- (NSString *)attitudesCountStr {
    
    NSString *result = [self countString:self.status.attitudes_count];
    
    return result ?: @" 赞";
}


- (NSString *)countString:(NSInteger)count {
    if (count <= 0) {
        return nil;
    } else if ( count < 10000) {
        return [NSString stringWithFormat:@"%zd", count];
    } else {
        CGFloat num = count / 1000 /10;
        if ((count / 1000) % 10 == 0) {
            return [NSString stringWithFormat:@"%.0f 万", num];
        } else {
            return [NSString stringWithFormat:@"%.1f 万", num];
        }
    }
}

@end
